//========================================
//Enemy Enitity Class
//========================================
//Rob Cavanaugh	Basic Class strucrure
//				AI
//Joji Fukika		AI
//Kevin Henry		Directsound
//Created:  02/15/2008
//Last Modified: 02/04/2009
//========================================
#pragma once
#include "GameObject.h"
#include "BaseEntity.h"
#include "Camera.h"
#include "EnemyOwnedState.h"
#include "StateMachine.h"
#include "GlobalDefines.h"
#include "BSPTree.h"

class Model;
struct Telegram;

class Enemy : public BaseEntity
{
private:

	// Pointer to the FSM
	StateMachine<Enemy>*		m_pEnemyState;

	BSPTree<int>			m_wayPoint;

	D3DXVECTOR3		m_disp;
	D3DXVECTOR3		m_disp2;
	D3DXVECTOR3		m_playerinfo;
	// Directsound
	LPDIRECTSOUNDBUFFER		m_BuffAwr;
	LPDIRECTSOUNDBUFFER		m_BuffAtk;
	LPDIRECTSOUNDBUFFER		m_BuffHit;
	LPDIRECTSOUNDBUFFER		m_BuffDie;

	float	m_radius;		//Collision radus check
	float   m_radarRad;		// Raduis for Attack checks
	float   m_meleeRad;
	bool	m_mRange;
	float   m_rotz;
	int		m_trigg;	// Triggers the state changes

public:

	Enemy(int id) : m_trigg(0), BaseEntity(id)
	{
		m_pEnemyState = new StateMachine<Enemy>(this);

		setXArc(1.0);
		setYArc(1.0);
		setZArc(1.0);

		m_pEnemyState->SetCurrentState(IdleState::Instance());
	}

	~Enemy();

	bool  HandleMessage(const Telegram& msg);

	// updates the game
	void updateFSM();

	// get method for changing state
	StateMachine<Enemy>*  getFSM()const{return m_pEnemyState;}

	void move(int direction, float anim_rate);
    bool create(LPDIRECT3DDEVICE9 device, std::string modelName);
	virtual void render(LPDIRECT3DDEVICE9 device);
	void update(float);

	float getRadius(){return m_radius;}
	float GetRadarRad() { return m_radarRad; }
	float GetMeleeRad() { return m_meleeRad; }

	void enemyAI();	// move the enemy
	D3DXVECTOR3 GetCoord();

	void SetTrigState(int trig);	// set trigger state
	int GetTrigState(); // get trigger set

	void SetPlayerInfo(D3DXVECTOR3 playerpos) { m_playerinfo = playerpos; }
	void ChasePlayer();

	int atkChance();
	void combat();
	void dead();
	void setRange(bool range);
	bool isPlayerOnRng() {return m_mRange;}

	bool checkSounds();
	void playAwrSound();
	void playDthSound();
	void releaseSounds();
};
